package com.socialhub.facebook;

public class FacebookException extends RuntimeException {

	public FacebookException() {
		super();
	}
	public FacebookException(String msg) {
		super(msg);
	}

	/**
	 * Something has gone wrong. Occasionally Twitter behaves strangely.
	 */
	public static class Unexplained extends FacebookException {
		public Unexplained(String msg) {
			super(msg);
		}

		private static final long serialVersionUID = 1L;
	}

	/**
	 * A timeout exception - probably caused by Twitter being overloaded.
	 */
	public static class Timeout extends FacebookException {
		public Timeout(String string) {
			super(string);
		}

		private static final long serialVersionUID = 1L;
	}

	/**
	 * A code 50X error (e.g. 502) - indicating something went wrong at
	 * Twitter's end. The API equivalent of the Fail Whale. Usually retrying in
	 * a minute will fix this.
	 */
	public static class E50X extends FacebookException {
		public E50X(String string) {
			super(string);
		}

		private static final long serialVersionUID = 1L;
	}

	/**
	 * A Forbidden exception. This is thrown if the authenticating used does not
	 * have the right to make a request.
	 */
	public static class E403 extends FacebookException {
		public E403(String string) {
			super(string);
		}

		private static final long serialVersionUID = 1L;
	}

	/**
	 * An unauthorised exception. This is thrown (eg) if a password is wrong or
	 * a login is required.
	 */
	public static class E401 extends FacebookException {
		public E401(String string) {
			super(string);
		}

		private static final long serialVersionUID = 1L;
	}

	private static final long serialVersionUID = 1L;

	private String additionalInfo = "";

	/**
	 * Wrap an exception as a FacebookException.
	 */
	FacebookException(Exception e) {
		super(e);
		// avoid gratuitous nesting of exceptions
		assert !(e instanceof FacebookException) : e;
	}


	public FacebookException(String string, String additionalInfo) {
		this(string);
		this.setAdditionalInfo(additionalInfo);
	}

	public void setAdditionalInfo(String additionalInfo) {
		this.additionalInfo = additionalInfo;
	}

	public String getAdditionalInfo() {
		return additionalInfo;
	}

	/**
	 * Indicates a 404: resource does not exist error from Twitter. Note: Can be
	 * throw in relation to suspended users.
	 */
	public static class E404 extends FacebookException {
		public E404(String string) {
			super(string);
		}

		private static final long serialVersionUID = 1L;
	}

	/**
	 * Indicates a rate limit error (i.e. you've over-used Twitter)
	 */
	public static class RateLimit extends FacebookException {
		public RateLimit(String string) {
			super(string);
		}

		private static final long serialVersionUID = 1L;
	}
}
